package com.flying.scorer.score;

import com.flying.refdata.model.equity.EquityInfo;
import com.flying.scorer.service.ScoreService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class ScorerWorker implements Runnable {
    private static Logger logger = LoggerFactory.getLogger(ScorerWorker.class);
    private ScoreService scoreService;
    private Iterable<EquityInfo> infos;
    private int beginDate;
    private int endDate;

    public ScorerWorker(ScoreService scoreService, Iterable<EquityInfo> infos, int beginDate, int endDate) {
        this.scoreService = scoreService;
        this.infos = infos;
        this.beginDate = beginDate;
        this.endDate = endDate;
    }

    @Override
    public void run() {
        try {
            scoreService.score(infos, beginDate, endDate);
        } catch (Throwable t) {
            logger.error("Failed to score data.", t);
        }
    }
}
